// DBVariable.cpp: implementation of the DBVariable class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "DBVariable.h"
#include "PropertyVisitor.h"
#include "PropertyExpression.h"
#include "PropertyOwner.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
namespace pa
{
	DBVariable::DBVariable()
	{

	}

	DBVariable::~DBVariable()
	{

	}
	
	void DBVariable::InitValue()
	{
	
		if(GetOwner() == NULL || this->Default().IsEmpty() 
			                  || m_bIsInitState)
		{
			return;
		}

		m_bIsInitState = TRUE;
		PropertyExpression expr(this->Default(), 
			this->GetOwner()->GetPropertyContainer());

		*static_cast<Variable*>(this) = (CString)expr.Caculate();
		m_bIsInitState = FALSE;
	}

	Property* DBVariable::Clone()
	{
		DBVariable* pVariable = new DBVariable;
		ASSERT(pVariable);

		this->CopyPropertyData(*pVariable,*this);
		pVariable->m_strPropertyField = this->m_strPropertyField;
		pVariable->m_strPropertyTable = this->m_strPropertyTable;
		return pVariable;
	}


	BOOL DBVariable::Accept(PropertyVisitor& visitor)
	{
		return visitor.Visit(this);
	}
};